def ss(a):    
    if a == 1: return False    
    test = True    
    m = a - 1    
    while m > 1:    
        if not a % m:    
            test = False                
            break    
        m -= 1        
    return test   
      
num = input()  
sp = []  
for i in range(len(num)):  
    for m in range(i + 1,len(num) + 1):  
        a = int(num[i:m]) 
        if ss(a):  
            sp += [a]  
print(max(sp) if sp else 0)